/*
 * @Author: long-xinyu2 2192763423@qq.com
 * @Date: 2025-04-01 10:09:57
 * @LastEditors: long-xinyu2 2192763423@qq.com
 * @LastEditTime: 2025-04-21 11:35:28
 * @FilePath: \algorithm\algorithm-training\lqb\acwing4_1.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<functional>
#include <bitset>
using namespace std;
using ull = unsigned long long;
using i128 = __int128_t;
//inline int inc(int x,int v,int mod){x+=v;return x>=mod?x-mod:x;}//代替取模+
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
#define int long long

const int N = 1010;

int f[N];

void solve()
{  
    int n,x,k;
    cin >> n >> x >> k;
    vector<int>brr(n + 10);
    vector<int>crr(n + 10);
    vector<int>w(n + 10);
    for(int i = 1; i <= n; i ++)
    {
        cin >> brr[i];
    }
    for(int i = 1; i <= n; i ++)
    {
        cin >> crr[i];
    }
    for(int i = 1; i <= n; i ++)
    {
        int xm = brr[i];
        while(xm)
        {
            if(xm % x == 0)
            {
                w[i]++;
                xm /= x;
            }
            else
            {
                w[i] += xm % x;
                xm -= xm % x;
            }
        }
    }
    for(int i = 1; i <= n; i ++)
    {
        for(int l = k; l >= w[i]; l --)
        {
            f[l] = max(f[l],f[l - w[i]] + crr[i]);
        }
    }
    int ans = 0;
    for(int i = 1; i <= k; i ++)
    {
        ans = max(ans,f[i]);
    }
    cout << ans << endl;
}
signed main()
{
    int t = 1;
    //cin >> t;
    while(t --)
    {
        solve();
    }
}
